Avoid calling g_list_model_get_n_items() all the time
authorTimm Bäder <mail@baedert.org>
Sun, 7 Jun 2020 11:11:33 +0000 (13:11 +0200)
committerTimm Bäder <mail@baedert.org>
Fri, 19 Jun 2020 03:26:25 +0000 (05:26 +0200)
These are used in hot paths, e.g. widget construction.

gtk/gtkshortcutcontroller.c
gtk/gtkwidget.c

index b11ea5da762eddd153039a49704956f01c095c05..d90a1814281e1fbecaabdb87f21ab4bf045c532d 100644 (file)
@@ -464,11 +464,11 @@ gtk_shortcut_controller_set_widget (GtkEventController *controller,
                                     GtkWidget          *widget)
 {
   GtkShortcutController *self = GTK_SHORTCUT_CONTROLLER (controller);
-  int i;
+  guint i, p;
 
   GTK_EVENT_CONTROLLER_CLASS (gtk_shortcut_controller_parent_class)->set_widget (controller, widget);
 
-  for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (controller)); i++)
+  for (i = 0, p = g_list_model_get_n_items (G_LIST_MODEL (controller)); i < p; i++)
     {
       GtkShortcut *shortcut = g_list_model_get_item (G_LIST_MODEL (controller), i);
       update_accel (shortcut, widget, TRUE);
index 483b99eefcda8c884ac6d053009dcd27f52e7805..cee8bbb1cde85b8d5801f77e258bdb870e97305f 100644 (file)
@@ -771,10 +771,10 @@ gtk_widget_base_class_init (gpointer g_class)
   else
     {
       GListModel *parent_shortcuts = G_LIST_MODEL (priv->shortcuts);
-      guint i;
+      guint i, p;
 
       priv->shortcuts = g_list_store_new (GTK_TYPE_SHORTCUT);
-      for (i = 0; i < g_list_model_get_n_items (parent_shortcuts); i++)
+      for (i = 0, p = g_list_model_get_n_items (parent_shortcuts); i < p; i++)
         {
           GtkShortcut *shortcut = g_list_model_get_item (parent_shortcuts, i);
           g_list_store_append (priv->shortcuts, shortcut);